home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX 6.2 Applications 1996 May
/
SGI IRIX 6.2 Applications 1996 May.iso
/
dist
/
impr_dev.idb
/
usr
/
impressario
/
src
/
libimp
/
impSeek.c.z
/
impSeek.c
Wrap
C/C++ Source or Header
|
1996-05-06
|
4KB
|
148 lines
/**************************************************************************
*
* Copyright (c) 1993 Silicon Graphics, Inc.
* All Rights Reserved
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
*
* The copyright notice above does not evidence any actual of intended
* publication of such source code, and is an unpublished work by Silicon
* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
* the property of Silicon Graphics, Inc. Any use, duplication or
* disclosure not specifically authorized by Silicon Graphics is strictly
* prohibited.
*
* RESTRICTED RIGHTS LEGEND:
*
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 52.227-7013,
* and/or in similar or successor clauses in the FAR, DOD or NASA FAR
* Supplement. Unpublished - rights reserved under the Copyright Laws of
* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
* Shoreline Blvd., Mountain View, CA 94039-7311
**************************************************************************
*
* File: impSeek.c
*
* Description: Internal routines for seeking in an SGI Image file.
*
**************************************************************************/
#ident "$Revision: 1.3 $"
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include "impI.h"
/**************************************************************************
*
* Function: _impSeekRow
*
* Description: Seeks in the specified image file to the row and channel
* specified.
*
* Parameters:
* image (I) - image file to seek
* row (I) - index of row to seek to. Note y = 0 is row 0, y = 1 is
* row 1, etc.
* channel (I) - channel number (0 based).
*
* Return: New image file pointer offset if successful. -1 is returned
* and IMPerrno is set if an error has occurred.
*
**************************************************************************/
off_t _impSeekRow(IMPImage *image, ushort_t row, ushort_t channel)
{
/*
* Validate the row and channel inputs
*/
if (_impBadRow(image, row, channel))
_impReturnError(IMP_ERR_BADROW);
/*
* Remember where we seeked to in terms of row and channel
*/
image->x = 0;
image->y = row;
image->z = channel;
/*
* Now compute the offset for the specified row and channel
* and seek to this offset.
*/
if (impIsVERBATIM(image)) {
switch (impDimension(image)) {
case 1:
return _impSeekOffset(image, image->start + _IMP_TABLES_START);
case 2:
return _impSeekOffset(image, image->start + _IMP_TABLES_START +
row * impXSize(image) * impRasterBPP(image));
case 3:
return _impSeekOffset(image, image->start + _IMP_TABLES_START +
(row * impXSize(image) +
channel * impXSize(image) * impYSize(image)) *
impRasterBPP(image));
default:
_impReturnError(IMP_ERR_BADDIM);
}
}
else if (impIsRLE(image)) {
switch (impDimension(image)) {
case 1:
return _impSeekOffset(image, image->start +
image->rowstart[0]);
case 2:
return _impSeekOffset(image, image->start +
image->rowstart[row]);
case 3:
return _impSeekOffset(image, image->start +
image->rowstart[row + channel * impYSize(image)]);
default:
_impReturnError(IMP_ERR_BADDIM);
}
}
_impReturnError(IMP_ERR_BADIMAGE);
}
/**************************************************************************
*
* Function: _impSeekOffset
*
* Description: Seeks in the specified image file to the specified offset.
* The seek is relative to the start of the file.
*
* Parameters:
* image (I) - image file to seek
* offset (I) - offset to seek to
*
* Return: New image file offset if successful. -1 is returned and
* IMPerrno is set if an error has occurred.
*
**************************************************************************/
off_t _impSeekOffset(IMPImage *image, off_t offset)
{
off_t off = offset;
if (image->offset != offset) {
image->offset = offset;
if (image->cache == IMPNoCache) {
if ((off = lseek(image->file, offset, SEEK_SET)) < 0)
_impReturnError(errno);
} else {
if (offset > image->cacheoffset + image->cachesize)
off = image->cachesize + image->cacheoffset;
}
}
return off;
}